home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Imaging / PolygonClipper / PolyClip.h < prev   
Encoding:
C/C++ Source or Header  |  1996-08-28  |  2.5 KB  |  76 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PolyClip.h
  3.  
  4.     Contains:    The polygon clipper! Performs intersection, union, difference.
  5.  
  6.     Written by:    Jens Alfke (based on algorithm by A. C. Kilgour)
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.     
  12.          <3>    10/24/94    jpa        Added PolyOutset. [1186719]
  13.          <2>      9/9/94    jpa        Added kShapeOutset (not yet implemented...)
  14.                                     [1178690]
  15.          <1>     6/15/94    jpa        first checked in
  16.          ---------------------------Moved to ODSOM project.
  17.          <1>      5/9/94    jpa        first checked in
  18.     
  19.     Theory Of Operation:
  20.         PolyClip( ) performs Boolean operations on any number of polygons.
  21.         Pass the number of polygons, an array of pointers to them, and the
  22.         operation you want performed:
  23.          kShapeIntersection computes the intersection of all the polygons.
  24.          kShapeUnion computes the union of all the polygons.
  25.          kShapeDifference subtracts all the other polygons from the first.
  26.         
  27.         PolySimplify( ) "simplifies" an input polygon by removing all
  28.         overlaps or self-intersections. F'rinstance, given a pentagram it
  29.         would return a five-pointed star. (This actually just calls
  30.         PolyClip with nPolys=1 and op=kShapeUnion.)
  31.         
  32.         PolyOutset( ) outsets the vertices of a polygon by a given distance,
  33.         or insets them if the distance is negative. The result may need
  34.         simplification, since parts of contours may flip over. The function
  35.         returns True if additional simplification may be needed.
  36.         
  37.         ** PolyClip is _not_ guaranteed to operate properly on self-
  38.         intersecting input polygons for operations other than union.
  39.         If this is a problem, just simplify the inputs beforehand.
  40.         
  41.         ** PolyClip uses winding-rule containment. This means that input
  42.         vertices must be ordered such that positive contours go clockwise
  43.         and holes go counterclockwise, as viewed in a coordinate system
  44.         where the positive Y axis extends downward (i.e. in the Macintosh
  45.         coordinate system, but not that of PostScript or traditional
  46.         computer graphics.)
  47. */
  48.  
  49.  
  50. #ifndef _POLYCLIP_
  51. #define _POLYCLIP_
  52.  
  53. #ifndef _ODTYPES_
  54. #include "ODTypes.h"
  55. #endif
  56.  
  57.  
  58. typedef enum {
  59.     kShapeIntersection,
  60.     kShapeUnion,
  61.     kShapeDifference,
  62.     
  63.     // For use internally by ODShape: do not pass to PolyClip:
  64.     kShapeOutset,
  65.     kShapeNoOp = -1
  66. } ODShapeOp; 
  67.  
  68.  
  69. void        PolyClip( ODSLong nPolys, const ODPolygon* polys[], ODShapeOp op, ODPolygon &result );
  70. void        PolySimplify( ODPolygon &dstPoly, const ODPolygon &srcPoly );
  71. // It's okay to use the same ODPolygon for input and output.
  72.  
  73. ODBoolean    PolyOutset( ODPolygon &poly, ODCoordinate distance );    // True if needs simplifying
  74.  
  75. #endif /*_POLYCLIP_*/
  76.